<template>
	<view class="content">
		<u-navbar :autoBack="true" :placeholder="true" bgColor="rgba(0, 0, 0, 0.0)">
			<view class="u-nav-slot" slot="left">
				<u-icon name="arrow-left" color="#fff" size="24"></u-icon>
			</view>
			<view class="u-nav-slot" slot="center">
				<view class="nav-text">
					积分兑换
				</view>
			</view>
		</u-navbar>
		<view class="head">
			<view class="head-left">
				<view class="head-title">
					我的积分：
				</view>
				<view class="head-num">
					{{userinfo.score || 0}}
				</view>
			</view>
			<image src="https://m.lqvvvv.com/images/big.png.png" mode=""></image>
		</view>
		<view class="list">
			<view class="item" v-for="(item,index) in list" :key="index">
				<view class="head-box" :style="{ backgroundImage: `url(${'https://m.lqvvvv.com' + item.image})` }">
				</view>
				<view class="integral">
					{{item.score}}积分
				</view>
				<view v-if="item.is_had == 0" class="btn1" @click="goplay(item.score,item.id)">兑换</view>
				<view v-else class="btn2">已兑换</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				list: [],
				userinfo: {}
			}
		},
		onLoad() {
			this.getList()
			this.getuserinfo()
		},
		methods: {
			goplay(score, id) {
				let app = this
				uni.showModal({
					title: '提示',
					content: '是否消耗' + score + '积分兑换此头像',
					success: function(res) {
						if (res.confirm) {
							console.log('用户点击确定');
							uni.showLoading({
								mask:true
							})
							let params = {
								avatar_id: id
							}
							app.$Request({
								method: 'POST',
								url: '/api/Avatar/exchange',
								data: params,
								ismsg: true,
							}).then(res => {
								console.log(res)
								uni.hideLoading()
								if (res.code == 1) {
									app.getList()
									app.getuserinfo()
								}
							})
						} else if (res.cancel) {
							console.log('用户点击取消');
						}
					}
				});
			},
			getuserinfo() {
				this.$Request({
					method: 'POST',
					url: '/api/user/getMyInfo',
					data: {},
					ismsg: false,
				}).then(res => {
					if (res.code == 1) {
						this.userinfo = res.data
					} else {
						this.userinfo = {}
					}
				})
			},

			getList() {
				let params = {
					page: 1,
					limit: 100
				}
				this.$Request({
					method: 'POST',
					url: '/api/Avatar/getList',
					data: params,
					ismsg: false,
				}).then(res => {
					console.log(res)
					if (res.code == 1) {
						this.list = res.data.data
					}
				})
			}
		}
	}
</script>

<style>
	page {
		background-color: #F7F8FC;
	}
</style>
<style lang="scss" scoped>
	.content {
		min-height: 100vh;
		background-image: url('https://m.lqvvvv.com/assets/static/index/nav-bg.png');
		background-repeat: no-repeat;
		background-size: 100% 900rpx;
		padding: 30rpx;

		.nav-text {
			font-size: 36rpx;
			font-weight: bold;
			color: #fff;
		}

		.head {
			display: flex;
			align-items: center;
			justify-content: space-between;

			.head-left {
				display: flex;
				align-items: center;

				.head-title {
					font-weight: bold;
					color: #2E314A;
					font-size: 32rpx;
				}

				.head-num {
					font-size: 40rpx;
					font-weight: bold;
					color: #5755F2;
				}
			}

			image {
				width: 149rpx;
				height: 149rpx;
			}
		}

		.list {
			display: flex;
			justify-content: space-between;
			flex-wrap: wrap;

			.item {
				width: 30%;
				padding: 20rpx 30rpx;
				background-color: #fff;
				border-radius: 30rpx;
				text-align: center;
				margin-top: 30rpx;

				.head-box {
					width: 130rpx;
					height: 130rpx;
					background-repeat: no-repeat;
					background-size: 100% 100%;
					margin: 0 auto;
				}

				.integral {
					color: #F24789;
					margin-top: 20rpx;
					font-size: 24rpx;
				}

				.btn1 {
					width: 112rpx;
					height: 48rpx;
					line-height: 48rpx;
					color: #fff;
					border-radius: 50px;
					text-align: center;
					margin: 0 auto;
					margin-top: 20rpx;
					font-size: 26rpx;
					background: linear-gradient(90deg, #C58AF0 0%, #6272ED 100%);
				}

				.btn2 {
					width: 112rpx;
					height: 48rpx;
					line-height: 48rpx;
					color: #fff;
					border-radius: 50px;
					text-align: center;
					margin: 0 auto;
					margin-top: 20rpx;
					font-size: 26rpx;
					background: linear-gradient(90deg, #c2c2c2 0%, #c2c2c2 100%);
				}

				.exchange {
					width: 130rpx;
					height: 60rpx;
					margin-top: 10rpx;
				}
			}
		}

	}
</style>